package com.tanhua.server.controller;

import com.tanhua.domain.db.UserInfo;
import com.tanhua.domain.vo.UserInfoVo;
import com.tanhua.server.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

//    注入逻辑类对象
    @Autowired
    UserService userService;


    /**
     * 首次登录个人信息完善
     */
    @RequestMapping(value = "/loginReginfo",method = RequestMethod.POST)
    public ResponseEntity loginReginfo
    (@RequestBody UserInfoVo userInfoVo) {
        //创建完整的UserInfo对象
        UserInfo userInfo = new UserInfo();
        //将用户填写的对象属性复制到UserInfo对象
        BeanUtils.copyProperties(userInfoVo,userInfo);
        //验证是否填充成功！
        log.debug("接受对象："+userInfo);
        //调用逻辑类代码
        userService.loginReginfo(userInfo);
        //返回responseEntity
        return ResponseEntity.ok(null);
   }

    /**
     * 人脸识别
     */
    @RequestMapping(value = "/loginReginfo/head",method = RequestMethod.POST)
    public ResponseEntity faceRecognition
    (MultipartFile headPhoto) {
//       调用逻辑处理类
         userService.faceRecognition(headPhoto);
//       返回数据
        return ResponseEntity.ok(null);
    }
}
